package wang;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.xml.ws.handler.MessageContext;

public class transferMoney extends JFrame{
	   private JLabel text1;
	   private JLabel text2;
	   private JTextField itemTextField;
	   private JButton transfer;
	   private JComboBox box1;
	   private JComboBox box2;
	   
	public transferMoney(){
		this.setTitle("My money");
	      this.setSize(600,400);
	      this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	      setupComponents();
	}
	private void setupComponents() {
		itemTextField = new JTextField(15);
		box1 = new JComboBox();
		box1.addItem("USD");
		box1.addItem("EUR");
		box1.addItem("GBP");
//		box1.addActionListener(new ActionListener() {
//			@Override
//			public void actionPerformed(ActionEvent e) {
//				// TODO Auto-generated method stub
//				setupComponents();
//			}
//		});
		text1 = new JLabel("transfer to");
		box2 = new JComboBox();
		box2.addItem("USD");
		box2.addItem("EUR");
		box2.addItem("GBP");
		String s1 = (String) box1.getSelectedItem();
		String s2 = (String) box2.getSelectedItem();
		
		transfer = new JButton("transfer");
		text2 = new JLabel("The money after transfer : ");
		
		
		if(s1.equals("USD")&&s2.equals("USD"))
		{
			 transfer.addActionListener(new ActionListener() {
		         public void actionPerformed(ActionEvent e) {
		        	 System.out.println(itemTextField.getText());
		            double money = Double.parseDouble(itemTextField.getText());
		            text2.setText("The money after transfer : "+money);
		         }      
		      });
		}
		else if(s1.equals("USD")&&s2.equals("EUR"))
		{
			transfer.addActionListener(new ActionListener() {
		         public void actionPerformed(ActionEvent e) {
		            double money = Double.parseDouble(itemTextField.getText());
		            double transferMoney = money/1.42;
		            text2.setText("The money after transfer : "+transferMoney);
		         }      
		      });
		}
		else if(s1.equals("USD")&&s2.equals("GBP"))
		{
			transfer.addActionListener(new ActionListener() {
		         public void actionPerformed(ActionEvent e) {
		            double money = Double.parseDouble(itemTextField.getText());
		            money = money/1.64;
		            
		         }      
		      });
		}
		else if(s1.equals("EUR")&&s2.equals("USD"))
		{
			transfer.addActionListener(new ActionListener() {
		         public void actionPerformed(ActionEvent e) {
		            double money = Double.parseDouble(itemTextField.getText());
		            money = money*1.42;
		            
		         }      
		      });
		}
		else if(s1.equals("EUR")&&s2.equals("EUR"))
		{
			transfer.addActionListener(new ActionListener() {
		         public void actionPerformed(ActionEvent e) {
		            double money = Double.parseDouble(itemTextField.getText());
		            
		         }      
		      });
		}
		else if(s1.equals("EUR")&&s2.equals("GBP"))
		{
			transfer.addActionListener(new ActionListener() {
		         public void actionPerformed(ActionEvent e) {
		            double money = Double.parseDouble(itemTextField.getText());
		            money = money/1.13;
		            
		         }      
		      });
		}
		else if(s1.equals("GBP")&&s2.equals("USD"))
		{
			transfer.addActionListener(new ActionListener() {
		         public void actionPerformed(ActionEvent e) {
		            double money = Double.parseDouble(itemTextField.getText());
		            money = money*1.64;
		            
		         }      
		      });
		}
		else if(s1.equals("GBP")&&s2.equals("EUR"))
		{
			transfer.addActionListener(new ActionListener() {
		         public void actionPerformed(ActionEvent e) {
		            double money = Double.parseDouble(itemTextField.getText());
		            money = money*1.13;
		            
		         }      
		      });
		}
		else if(s1.equals("GBP")&&s2.equals("GBP"))
		{
			transfer.addActionListener(new ActionListener() {
		         public void actionPerformed(ActionEvent e) {
		            double money = Double.parseDouble(itemTextField.getText());
		            
		         }      
		      });
		}
		
		JPanel subPanel = new JPanel();
		add(subPanel);
		subPanel.add(itemTextField);
		subPanel.add(box1);
		subPanel.add(text1);
		subPanel.add(box2);
		subPanel.add(transfer);
		JPanel subPanel2 = new JPanel();
		add(subPanel2);
		subPanel2.add(text2);
		add(subPanel, BorderLayout.NORTH);
	    add(text2, BorderLayout.CENTER);
		
	}
	 public void showMe() {
	      this.setVisible(true);
	   }

}
